package com.lw.ssm.controller;


import com.github.pagehelper.PageInfo;
import com.lw.ssm.dto.R;
import com.lw.ssm.pojo.Student;
import com.lw.ssm.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/3/10 10:12
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    private StudentService studentService;

    @Autowired
    public void setStudentService(StudentService studentService) {
        this.studentService = studentService;
    }

    @GetMapping("/find/{id}")
    public R findById(@PathVariable Long id){
        Student student = studentService.findById(id);
        return R.setOK(student);
    }

    @GetMapping("/find")
    public R findAll(@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "2") int pageSize){
        PageInfo<Student> pageInfo = studentService.findAll(pageNum, pageSize);
        return R.setOK(pageInfo);
    }

    @PostMapping("/add")
    public R addStudent(@RequestBody Student student){
        studentService.addStudent(student);
        return R.setOK();
    }
    @PostMapping("/add/update")
    public R updateStudent(@RequestBody Student student){
        studentService.updateById(student);
        return R.setOK();
    }

    @GetMapping("/add/del/{id}")
    public R deleteStudent(@PathVariable Long id){
        studentService.deleteById(id);
        return R.setOK();
    }


}
